package com.yodawnla.littleWar.player;

import org.anddev.andengine.util.MathUtils;

import com.yodawnla.littleWar.card.CardMgr;
import com.yodawnla.littleWar.card.Deck;
import com.yodawnla.littleWar.card.HeroCard;
import com.yodawnla.littleWar.card.HandCard;
import com.yodawnla.littleWar.system.Values;

public class Npc
{
	int mDifficult = 0;
	Deck mDeck;
	boolean mIsRemote = false;
	CardMgr mCardMgr = CardMgr.getInstance();
	
	static Npc instance = null;
	
	public static Npc getInstance()
	{
		if (instance == null)
			instance = new Npc();
		return instance;
	}
	
	public Npc()
	{
		mDeck = new Deck();
		for(int i = 0; i < 7; i++)
		{
			HandCard card = mCardMgr.createHandCard("s!" + Values.HandCardType.Red + "!0");
			mDeck.addCardToDeck(card);
			//mCardMgr.getScene().getEntity2().attachChild(card);
			card.showDamageText(false);
			
			card = mCardMgr.createHandCard("s!" + Values.HandCardType.Green + "!0");
			mDeck.addCardToDeck(card);
			//mCardMgr.getScene().getEntity2().attachChild(card);
			card.showDamageText(false);
			
			card = mCardMgr.createHandCard("s!" + Values.HandCardType.Blue + "!0");
			mDeck.addCardToDeck(card);
			//mCardMgr.getScene().getEntity2().attachChild(card);
			card.showDamageText(false);
		}
	}
	
	public void setIsRemote(boolean isRemote)
	{
		mIsRemote = isRemote;
	}
	
	public boolean getIsRemote()
	{
		return mIsRemote;
	}
	
	public void createEnemyHero(String data)
	{
		HeroCard heroCard = mCardMgr.createHeroCard(data);
		mDeck.setHeroCard(heroCard);
		heroCard.setPosition(273, 220);
		//mCardMgr.getScene().getEntity1().attachChild(heroCard);
	}
	
	public void setDifficult(int difficult)
	{
		int minDamage = 0;
		int maxDamage = 0;
		switch(difficult)
		{
		case 0:
			minDamage = 1;
			maxDamage = 5;
			createEnemyHero("5!0!8!1!100!100!12!50!0");//job!id!star!lv!maxHp!hp!atk!cost!exp!
			break;
		}
		
		for(int i = 0; i < mDeck.getCardListSize(); i++)
			mDeck.getCard(i).setDamage(MathUtils.random(minDamage, maxDamage));
		
		mDeck.init();
		mDeck.putHandCard();
	}
	
	public Deck getDeck()
	{
		return mDeck;
	}
	
	public HandCard getCurrCard()
	{
		HandCard card = null;
		if(mIsRemote)
		{
			//TODO
		}
		else
		{
			card = mDeck.getRandomCard();
			card.showDamageText(true);
		}
		return card;
	}
}